package com.zfx.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @author: zfx
 * @version: 1.0
 * @time: 2020-05-10 13:40
 * <p>
 * 修改历史：
 * 修改日期      修改人员    版本    内容
 * 2020-05-10   zfx       1.0
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object userId = request.getSession().getAttribute("userId");
        if(userId == null) {
            response.sendRedirect(request.getContextPath()+"/login.html");
            return false;
        } else {
            return true;
        }
    }
}
